package adata;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;

import forms.FileUploadForm;

public class FileUploadAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		FileUploadForm myForm = (FileUploadForm) form;

		// Process the FormFile
		FormFile myFile = myForm.getMyFile();
		String contentType = myFile.getContentType();
		String fileName = myFile.getFileName();
		int fileSize = myFile.getFileSize();
		byte[] fileData = myFile.getFileData();
		request.setAttribute("filename", fileName);
		request.setAttribute("filesize", fileSize);
		List<String> words = new ArrayList<String>();
		words.add("hello");
		words.add("world");
		request.setAttribute("words", words);
		return mapping.findForward("success");
		
	}
}
